package com.daryl.jcu_project1_creditscoreform;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

public class Credit_score_form_sec_e extends Activity{
	
	private Button BtnNextPage;
	private int mYear;
	private int mMonth;
	private int mDay;
	private Button dateApproveBtn1;
	private Button dateApproveBtn2;
	static final int DATE_DIALOG_ID = 0;
	static final int DATE_DIALOG_ID2 = 1;
	private Button btnBackPage;
	private TextView etDateApprove;
	private TextView etDateApprove2;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.credit_score_form_sec_e);
		BtnNextPage = (Button) findViewById(R.id.nextPageBtn);
		BtnNextPage.setOnClickListener(nextPage());
		dateApproveBtn1 = (Button) findViewById(R.id.dateApproveBtn1);
		dateApproveBtn2 = (Button) findViewById(R.id.dateApproveBtn2);
		etDateApprove = (TextView) findViewById (R.id.etDateApprove);
		etDateApprove2 = (TextView) findViewById (R.id.etDateApprove2);
		btnBackPage = (Button) findViewById(R.id.backPageBtn);
		btnBackPage.setOnClickListener(backPage());
		
		dateApproveBtn1.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				showDialog(DATE_DIALOG_ID);
			}
		});
		
		dateApproveBtn2.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				showDialog(DATE_DIALOG_ID2);
			}
		});
	}
	
	///For Date Application Given
		@Override 
		protected Dialog onCreateDialog(int id){
			switch(id) {
			case DATE_DIALOG_ID:
				return new DatePickerDialog(this,mDateSetListener, mYear, mMonth,mDay);
			
			case DATE_DIALOG_ID2:
				
				return new DatePickerDialog(this,mDateSetListener2, mYear, mMonth,mDay);
			}
			return null;
		}
		
		 
		
	     
		//the callback receive when the user "sets" the date in the dialog
		private DatePickerDialog.OnDateSetListener
		mDateSetListener = new DatePickerDialog.OnDateSetListener() {
			 
			public void onDateSet(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				
				//get the current date
				final Calendar c = Calendar.getInstance();
				mYear = year;
				mMonth = monthOfYear;
				mDay = dayOfMonth;
				
				
				      
				
				updateDisplay();
				
			}
			
			 
		        
		};
		
		//updates the dates in the textView
		private void updateDisplay(){
			etDateApprove.setText(new StringBuilder()
					//month is 0 base so add 1
					.append(mMonth + 1).append("-")
					.append(mDay).append("-")
					.append(mYear).append(" "));
		}
		
		//the callback receive when the user "sets" the date in the dialog
				private DatePickerDialog.OnDateSetListener
				mDateSetListener2 = new DatePickerDialog.OnDateSetListener() {
					 
					public void onDateSet(DatePicker view, int year, int monthOfYear,
							int dayOfMonth) {
						
						//get the current date
						final Calendar c = Calendar.getInstance();
						mYear = year;
						mMonth = monthOfYear;
						mDay = dayOfMonth;
						
						
						      
						
						updateDisplay2();
						
					}
					
					 
				        
				};
				
				//updates the dates in the textView
				private void updateDisplay2(){
					etDateApprove2.setText(new StringBuilder()
							//month is 0 base so add 1
							.append(mMonth + 1).append("-")
							.append(mDay).append("-")
							.append(mYear).append(" "));
				}
	

	private OnClickListener nextPage() {
		final Context context = this;
		return new OnClickListener() {
			public void onClick(View v) {

				Intent intent = new Intent(context,
						Credit_score_form_sec_f.class);
				startActivity(intent);

			}
		};
	}
	
	private OnClickListener backPage() {
		final Context context = this;
		return new OnClickListener() {
			public void onClick(View v) {

				Intent intent = new Intent(context,
						Credit_score_form_sec_d.class);
				startActivity(intent);

			}
		};
	}

}
